#!/bin/sh

base_module_name=@base_module_name@
base_module="${base_module_name}.ko"
payload_module1_name=@payload_module1_name@
payload_module1="payload1/${payload_module1_name}.ko"
payload_module3_name=@payload_module3_name@
payload_module3="payload3/${payload_module3_name}.ko"
verificator_module_name=@verificator_module_name@
verificator_module="interception_info_verificator/${verificator_module_name}.ko"

if ! @INSMOD@ "$base_module"; then
    printf "Failed to load base module.\n"
    exit 1
fi

if ! @INSMOD@ "$payload_module1"; then
    printf "Failed to load payload module 1.\n"
    @RMMOD@ "$base_module_name"
    exit 1
fi

if ! @INSMOD@ "$payload_module3"; then
    printf "Failed to load payload module 3.\n"
    @RMMOD@ "$payload_module1_name"
    @RMMOD@ "$base_module_name"
    exit 1
fi

if ! @INSMOD@ "$verificator_module" "situation=2"; then
    printf "Verification failed.\n"
    @RMMOD@ "$payload_module3_name"
    @RMMOD@ "$payload_module1_name"
    @RMMOD@ "$base_module_name"
    exit 1
fi

if ! @RMMOD@ "$verificator_module_name"; then
    printf "Failed to unload verificator module."
    @RMMOD@ "$payload_module3_name"
    @RMMOD@ "$payload_module1_name"
    @RMMOD@ "$base_module_name"
    exit 1
fi

if ! @RMMOD@ "$payload_module1_name"; then
    printf "Failed to unload payload module 1.\n"
    exit 1
fi

if ! @RMMOD@ "$payload_module3_name"; then
    printf "Failed to unload payload module 3.\n"
    exit 1
fi

if ! @RMMOD@ "$base_module_name"; then
    printf "Failed to unload base module."
    exit 1
fi
